<?php
header("Content-Type: text/html; charset=iso-8859-1");
require('include.php');
foreach($_GET as $key => $val){
	$$key = $val;
}
if(!$val) $val = 'VBCLL';
$v = new vcalendar();
$tablename = (isset($table)) ? "table".$table : "table";                          // initiate new CALENDAR
$table = (!empty($_SESSION[$tablename])) ? $_SESSION[$tablename] : "";
$mytable = unserialize($table);
foreach($mytable->rows as $row){
	$match = new match($row->cols['no']);
	$year = substr($match->date, 0,4); 
	$month = substr($match->date, 5, 2); 
	$day = substr($match->date, 8, 2);
	$hour = substr($match->heure,0,2);
	$min = substr($match->heure,3,2);
	$sec = substr($match->heure,6,2);
	$start = strtotime($match->date." ".$match->heure);
	$end = $start + 60*90;
	$ends = getdate($end);
	$end = 
	$salle = new salle($match->salle);
	if($marqueur1 = new membre($match->marqueur1)) $marq1 = ($marqueur1->id) ? $marqueur1->prenom." ".$marqueur1->nom." ".$marqueur1->mobile : "";
	if($marqueur2 = new membre($match->marqueur2)) $marq2 = ($marqueur2->id) ? $marqueur2->prenom." ".$marqueur2->nom." ".$marqueur2->mobile : "";

	$sal = $salle->nom." ".$salle->localite;
	$description = $sal." ".$marq1." ".$marq2;
	$e = new vevent();                             // initiate a new EVENT
	$e->setProperty( 'dtstart'
	               ,  $year, $month, $day, $hour, $min, $sec );  // 24 dec 2006 19.30
	$e->setProperty('dtend', $ends['year'], $ends['mon'], $ends['mday'], $ends['hours'], $ends['minutes'], $ends['seconds']);
	$e->setProperty( 'description'
	               , $sal );    // describe the event
	$e->setProperty( 'location'
	               , $sal );                     // locate the event
	$e->setProperty( 'summary'
			         ,$match->equipe." ".$match->local." - ".$match->visiteur );                     // locate the event

	$v->addComponent( $e );                        // add component to calendar
}

$str = $v->createCalendar();         
$filename = "cal_$val.ics";
Header("Content-Disposition: attachment; filename=$filename");
Header("Content-Length: ".strlen($str));
header("Pragma: no-cache"); 
header("Expires: 0");
Header("Connection: close");
header("Content-type: text/calendar");
echo $str;					
?>